package com.siqi.hr.system.organization.controller;

import com.siqi.hr.system.common.model.ModuleType;
import com.siqi.hr.system.organization.entity.Employee;
import com.siqi.hr.system.organization.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * 权限菜单信息维护控制器
 * @author     xiaogq
 * Created by xiaogoingqin on 2016/7/24.
 */
@Controller
@RequestMapping("Menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 获取左边权限菜单控制器方法(xiaogq)
     * @param request
     * @param session
     * @return
     */
    @RequestMapping(value = "initMenu", method = RequestMethod.GET)
    @ResponseBody
    public List<Map<String, Object>> initMenu(HttpServletRequest request, HttpSession session) {
        Employee emp = (Employee)session.getAttribute("emp");
        //获取当前用户登录模块id(1:系统模块，2：业务模块默认是系统模块)
        int moduleId = request.getParameter("moduleId") == null ? 1 : Integer.parseInt(request.getParameter("moduleId"));
        ModuleType mudule = ModuleType.getModuleType(moduleId);
        List<Map<String, Object>> menuList = menuService.getInitMenuList(emp.getRole().getId(), mudule);
        return menuList;
    }

}
